var ctx = ctx;
var patientId=$("#patientId").val();
var patVisitId=$("#patVisitId").val();
var bedRecId=$("#bedRecId").val();
$(function(){
    return loadDiv('turnOutForm',ctx+'/nurse/wardCirculation/findInfoByTurnOutParam?patientId='+patientId+'&patVisitId='+patVisitId+"&bedRecId="+bedRecId);
    //loadDiv('turnOutWardPatientListDiv',ctx+'/nurse/wardCirculation/findWaitTurnOutPatientList');
});

function showTurnOutForm(patientId,patVisitId){
    var bedRecId = $("#bedRecId").val();
    $("#turnOutWardPatientListDiv").attr("class","col-lg-8");
    $("#turnOutForm").show('normal');
    hideShowTableTd("turnOutWardPatientListDiv", '3,4,5', '2');
    return loadDiv('turnOutForm',ctx+'/nurse/wardCirculation/findInfoByTurnOutParam?patientId='+patientId+'&patVisitId='+patVisitId+"&bedRecId="+bedRecId);
}

function closeTurnOutForm(){
    $("#turnOutWardPatientListDiv").attr("class","col-lg-12");
    $("#turnOutWardPatientListDiv").show('normal');
    hideShowTableTd("turnOutWardPatientListDiv", '3,4,5', '1');
    $("#turnOutForm").attr("style","display: none");
}


function formTurnOutLoad(divId,formId,url,hrefUrl,patientId,visitId){
    if(flag){
        /*判断病人是否有包床，如果有包床，解除包床后再取消移入*/
        $.ajax({
            type: "POST",
            url: ctx+"/nurse/bedRec/validBedOccupy?patientId="+patientId+"&visitId="+visitId,
            dataType: "json",
            success: function (data) {
                if (data.code == "success") {
                    if ($('#' + formId).parsley().validate()) {
                        flag=false;
                        $("#"+formId+" input,#"+formId+" select").removeAttr("disabled");
                        $.ajax({
                            type: "POST",
                            data:$("#"+formId).serialize(),
                            url: url,
                            dataType: "json",
                            success: function(data) {
                                // alert(data.code);
                                if (data.code == "1" || data.code==1) {
                                    if (data.data!=null&&data.data!=''){
                                        var datas = eval(data.data);
                                        for (var i = 0; i < datas.length; i++) {
                                            if (datas[i].results == "1") {
                                                toastr.info(datas[i].message);
                                            }
                                        }
                                    }
                                }else if(data.code==0 || data.code=='0'){
                                    toastr.success('移出病人成功');
                                    parent.layer.closeAll();
                                    parent.refesh();
                                }else {
                                    flag=true;
                                    toastr.error(data.data);
                                }
                            },
                            error: function(data) {
                                toastr.error('网络连接错误,请检查网络');
                                flag=true;
                            }
                        });
                    }
                } else if (data.code == "info") {
                    toastr.info(data.data);
                } else {
                    toastr.error("移出病人失败");
                }
            },
            error: function (data) {
                toastr.error('网络连接错误,请检查网络');
            }
        });

    }
    return false;
}